home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / UTIL / GET_NS.CPP < prev    next >
C/C++ Source or Header  |  1994-12-13  |  2KB  |  94 lines

  1. #include "..\au.hpp"
  2. /*************************************************************************/
  3. static BOOLEAN inside_partial(AU *au, char *file_name, char *partial)
  4. {
  5.     char partial_piece[80];
  6.     char *ptr, *cur_pos;
  7.     int len;
  8.     BOOLEAN more = TRUE;
  9.  
  10.     if (partial[0] == '\0')
  11.         return TRUE;
  12.  
  13.     cur_pos = partial;
  14.     while (more)
  15.     {
  16.         ptr = strchr(cur_pos, ' ');
  17.         if (ptr == NULL)
  18.         {
  19.             strcpy(partial_piece, cur_pos);
  20.             more = FALSE;
  21.         }
  22.         else
  23.         {
  24.             len = ptr - cur_pos;
  25.             strncpy(partial_piece, cur_pos, len);
  26.             ltrim(partial_piece);
  27.             partial_piece[len] = '\0';
  28.             cur_pos = ptr+1;
  29.             while (*cur_pos == ' ')
  30.                 cur_pos++;
  31.         }
  32.         if (partial_piece[0] == '\0')
  33.             break;
  34.         if (wildcard_compare(au, file_name, partial_piece))
  35.             return TRUE;
  36.     }
  37.     return FALSE;
  38. }
  39. /*************************************************************************/
  40. void get_ns(AU *au, char *partial, ARC_HANDLE *arc_handle, LISTPTR *arc_paths,
  41.             LISTPTR *arc_files, LISTPTR *paths, LISTPTR *too_long,
  42.             LISTPTR *hidden, LISTPTR *dangerous)
  43. {
  44.     ARC_RECORD record;
  45.     int  ret_code;
  46.     LIST *el;
  47.  
  48.     for (;;)
  49.     {
  50.         ret_code = arc_handle->get_record(au, &record);
  51.         if (ret_code == EOF)
  52.             break;
  53.         else if (ret_code == -2)
  54.             break;
  55.         else if (ret_code == -3)
  56.             break;
  57.  
  58.         if (!inside_partial(au, record.name, partial))
  59.             continue;
  60.  
  61.         if (record.path[0] != '\0')
  62.         {
  63.             for (el = paths->head; el != NULL; el=el->next)
  64.             {
  65.                 if (stricmp(record.path, el->data)==0)
  66.                     break;
  67.             }
  68.             if (el == NULL)
  69.                 paths->add(ltrim(record.path));
  70.  
  71.             for (el = dangerous->head; el != NULL; el=el->next)
  72.             {
  73.                 if (stricmp(record.path, el->data)==0)
  74.                     break;
  75.             }
  76.             if (el == NULL)
  77.             {
  78.                 /* Path is not relative */
  79.                 if (strstr(record.path, "..") != NULL || record.path[0] == '\\')
  80.                     dangerous->add(ltrim(record.path));
  81.             }
  82.         }
  83.         if (!is_dos_name(record.name))
  84.             too_long->add(record.name);
  85.  
  86.         if (record.attrib & (0x02 | 0x04))
  87.             hidden->add(record.name);
  88.  
  89.         arc_paths->add(ltrim(record.path));
  90.         arc_files->add(record.name);
  91.     }
  92.     return;
  93. }
  94.